//
//  NSDate+Convert.m
//  biz
//
//  Created by 李小龙 on 2017/3/21.
//  Copyright © 2017年 jieshuibao. All rights reserved.
//

#import "NSDate+Convert.h"

@implementation NSDate (Convert)
+(NSString *)stringFromTimestamp:(long)timestamp
{
    NSTimeInterval time = timestamp/1000.00;
    NSDate *detaildate=[NSDate dateWithTimeIntervalSince1970:time];
    NSDateFormatter *dateFormatter = [NSDateFormatter sharedDateFormatter];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    
    return [dateFormatter stringFromDate: detaildate];
}

+(NSString *)stringFromTimestamp:(long)timestamp dateFormat:(NSString *)format
{
    NSTimeInterval time = timestamp/1000.00;
    NSDate *detaildate=[NSDate dateWithTimeIntervalSince1970:time];
    NSDateFormatter *dateFormatter = [NSDateFormatter sharedDateFormatter];
    [dateFormatter setDateFormat:format?:@"yyyy-MM-dd HH:mm:ss"];
    
    return [dateFormatter stringFromDate: detaildate];
}

+(long)timeFromTimeStr:(NSString *)timeStr
{
    NSDateFormatter *dateFormatter = [NSDateFormatter sharedDateFormatter];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate *date = [dateFormatter dateFromString:timeStr];
    NSString *timeStampStr = [NSString stringWithFormat:@"%ld", (long)[date timeIntervalSince1970]*1000];
    
    return [timeStampStr integerValue];
}

@end
